package org.example.test_qlexpress.function;

import com.ql.util.express.Operator;

public class LtFunction extends Operator {
    public Object executeInner(Object[] objects) throws Exception {
        if (objects == null || objects.length == 0) {
            throw new RuntimeException("未传入任何参数。");
        }
        if (objects.length < 3) {
            throw new RuntimeException("参数至少是3个。");
        }
        Object x = objects[0];
        Object a = objects[1];
        if (!(x instanceof Comparable && a instanceof Comparable)) {
            throw new RuntimeException("前两个参数不许都是可比较的。");
        }
        Comparable _x = (Comparable) x;
        Comparable _a = (Comparable) a;
        if (_x.compareTo(_a) < 0) {
            return objects[2];
        }
        if (objects.length > 3) {
            return objects[3];
        }
        return 0;
    }
}
